<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: table_common_admincp_cmenu.php 27806 2012-02-15 03:20:46Z svn_project_zhangjie $
 */

if(!defined('IN_DISCUZ')) {
    exit('Access Denied');
}

class table_home_video_view extends discuz_table
{
    public function __construct() {

        $this->_table = 'home_video_view';
        $this->_pk    = 'id';

        parent::__construct();
    }

    public function get_view_num($id){
        if(empty($id)){
            return DB::result_first('select count(id) from %t',array($this->_table));
        }else{
            return DB::result_first('select count(id) from %t where v_id=%d', array($this->_table, $id));
        }
    }

    public function get_all_view($v_id='', $start='', $pageSize='0'){
        if($pageSize != 0){
            if($v_id == ''){
                return DB::fetch_all("SELECT * FROM %t vi LEFT JOIN %t v ON vi.v_id=v.v_id LEFT JOIN %t m ON vi.m_id=m.uid ORDER BY vi.view_time DESC LIMIT %d,%d", array($this->_table, 'home_video', 'common_member', $start, $pageSize));
            }else{
                return DB::fetch_all("SELECT * FROM %t vi LEFT JOIN %t v ON vi.v_id=v.v_id LEFT JOIN %t m ON vi.m_id=m.uid WHERE vi.v_id=%d ORDER BY vi.view_time DESC LIMIT %d,%d", array($this->_table, 'home_video', 'common_member', $v_id , $start, $pageSize));
            }
        }else{
            if($v_id == ''){
                return DB::fetch_all("SELECT * FROM %t vi LEFT JOIN %t v ON vi.v_id=v.v_id LEFT JOIN %t m ON vi.m_id=m.uid ORDER BY vi.view_time DESC", array($this->_table, 'home_video', 'common_member'));
            }else{
                return DB::fetch_all("SELECT * FROM %t vi LEFT JOIN %t v ON vi.v_id=v.v_id LEFT JOIN %t m ON vi.m_id=m.uid WHERE vi.v_id=%d ORDER BY vi.view_time DESC", array($this->_table, 'home_video', 'common_member', $v_id));
            }
        }
    }

    public function get_view_by_id($id){
        return DB::fetch_first('select * from %t where id=%d',array($this->_table,$id));
    }

    public function del_view($id){
        return DB::query('delete from %t where id=%d',array($this->_table,$id));
    }

}

?>